<template>
	<view>
	<view class="noLogin" v-if="isEmpty">
		<empty :emptyImg="emptyImg" :emptyTxt="emptyTxt"></empty>
	</view>
	<view class="coupon" v-if="!isEmpty">
		<view  class="couponList" v-for="(item, index) in couponList" :key="index">
			<view class="topIcon">
				<image src="https://yunxingzhan.oss-cn-hangzhou.aliyuncs.com/miniprogram/images/images/coupon.png"></image>
			</view>
			<view class="middlePart">
				<view class="title">{{item.reduce_price}}元优惠券</view>
				<view class="info">{{item.min_price}}</view>
				<u-button shape="circle" size="medium" hover-class="none" 
				:custom-style="customStyle" @click="saveCouPon(item.coupon_id)">立即领取</u-button>
				<view class="dateInfo">有效期：{{item.expire_day}}天</view>
			</view>
			<view class="cutLine"></view>
			<view class="bottomPart">
				<view class="remarkTitle">优惠券说明</view>
				<view>{{item.name}}</view>
			</view>
		</view>
		<u-loadmore :status="status" v-if="!isEmpty" color="#909399"/>
	</view>
	<login-model ref="loginModel"></login-model>
	<hoverMenu></hoverMenu>
	</view>
</template>

<script>
	import hoverMenu from "@/components/public/sa-hover-menu.vue";
	import loginModel from "@/components/public/loginModel.vue";
	import empty from "@/components/public/empty.vue";
	import {userListCoupon,getCoupon} from "@/common/api.js";
	export default {
		components: {
			empty,
			loginModel,
			hoverMenu
		},
		data() {
			return {
				customStyle: {
					color: '#f5fdfe',
					backgroundColor:"#20cbd4",
					border:"#20cbd4",
					marginBottom:"30rpx"
				},
				couponList: [],
				status: 'loadmore',
				pageSize: 3,
				pageStart: 1,
				total:0,
				isEmpty:false,
				emptyImg:"https://yunxingzhan.oss-cn-hangzhou.aliyuncs.com/miniprogram/images/images/empty_goods.png",
				emptyTxt:"暂无优惠券",
			}
		},
		onShow: function() {
			this.couponList=[];
			this.pageStart = 1;
			this.selectCouponList();
		},
		onReachBottom: function() {
			if(this.total/(this.pageStart*this.pageSize)>1){
				this.pageStart++;
				this.selectCouponList();
			}else{
				this.status = 'nomore';
			}
		},
		methods: {
			floatTouchClick(index){
				this.$uniApi.floatTouch(index);
			},
			selectCouponList(){
				userListCoupon(this,{page:this.pageStart,limit:this.pageSize,type:0});
			},
			saveCouPon(coupon_id){
				getCoupon(this,{coupon_id:coupon_id})
			}
		}
	}
</script>

<style>
	page{
		font-family: PingFang SC;
		background: #20cbd4;
	}
	.noLogin{
			width: 600rpx;
			height: 1000rpx;
			border-radius: 10px 10px 10px 10px;
			position: relative;
			top: 50rpx;
			left: 72rpx;
			background-color: #fff;
		}
	.coupon{
		padding: 20rpx;
	}
	.couponList{
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.topIcon{
		background-color: #fff;
		width: 200rpx;
		height: 200rpx;
		border-radius: 100rpx;
		position: relative;
		z-index: 9;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.topIcon image{
		width: 80%;
		height: 80%;
	}
	.middlePart{
		width: 600rpx;
		height: 450rpx;
		border-radius: 10px 10px 0 0;
		background-image: -webkit-radial-gradient(bottom left,circle,#20cbd4,#20cbd4 8px,transparent 8px),-webkit-radial-gradient(bottom right,circle,#20cbd4,#20cbd4 8px,transparent 8px);
		background-image: radial-gradient(circle at bottom left,#20cbd4,#20cbd4 8px,transparent 8px),radial-gradient(circle at bottom right,#20cbd4,#20cbd4 8px,transparent 8px);
		padding: 55px 0 20px 0;
		position: relative;
		top:-100rpx;
		background-color: #fff;
		text-align: center;
	}
	.title{
		font-size: 40rpx;
		font-weight: 600;
		margin-bottom: 30rpx;
	}
	.info{
		margin-bottom: 30rpx;
	}
	.dateInfo{
		color: #909399;
	}
	.cutLine{
		border-top: 2rpx #20cbd4 dashed;
		width: 95%;
		position: relative;
		top:-100rpx
	}
	.bottomPart{
		background-color: #fff;
		width: 600rpx;
		border-radius: 0 0 20rpx 20rpx;
		background-image: -webkit-radial-gradient(top left,circle,#20cbd4,#20cbd4 8px,transparent 8px),-webkit-radial-gradient(top right,circle,#20cbd4,#20cbd4 8px,transparent 8px);
		background-image: radial-gradient(circle at top left,#20cbd4,#20cbd4 8px,transparent 8px),radial-gradient(circle at top right,#20cbd4,#20cbd4 8px,transparent 8px);
		position: relative;
		top: -100rpx;
		padding: 40rpx 30rpx;
	}
	.remarkTitle{
		font-size: 30rpx;
		font-weight: 500;
		margin-bottom: 30rpx;
	}
</style>
